<div ng-controller="Umbraco.Dialogs.LoginController">

    <div id="login" class="umb-modalcolumn umb-dialog" ng-class="{'show-validation': loginForm.$invalid}" ng-cloak konami-code="activateKonamiMode()">

        <div class="login-overlay__background-image" ng-if="backgroundImage" ng-style="{'background-image':'url(' + backgroundImage + ')'}"></div>

        <div class="login-overlay__logo">
            <img ng-src="assets/img/application/logo.png" ng-srcset="assets/img/application/logo@2x.png 2x, assets/img/application/logo@3x.png 3x">
        </div>

        <div ng-show="invitedUser != null" class="umb-login-container">

            <form name="inviteUserPasswordForm" novalidate="" ng-submit="inviteSavePassword()" val-form-manager>
                <div class="form" ng-if="inviteStep === 1">
                    <h1 style="margin-bottom: 10px; text-align: left;">Hi, {{invitedUser.name}}</h1>
                    <p style="line-height: 1.6; margin-bottom: 25px;">
                        <localize key="user_userinviteWelcomeMessage">Welcome to Umbraco! Just need to get your password and avatar setup and then you're good to go</localize>
                    </p>

                    <div class="control-group" ng-class="{error: setPasswordForm.password.$invalid}">
                        <label>
                            <localize key="user_newPassword">New password</localize>
                            <small style="font-size: 13px;">{{invitedUserPasswordModel.passwordPolicyText}}</small>
                        </label>
                        <input type="password" ng-model="invitedUserPasswordModel.password" name="password" class="-full-width-input" umb-auto-focus required val-server-field="value" ng-minlength="{{invitedUserPasswordModel.passwordPolicies.minPasswordLength}}" />
                        <span class="help-inline" val-msg-for="password" val-toggle-msg="required"><localize key="user_passwordIsBlank">Your new password cannot be blank!</localize></span>
                        <span class="help-inline" val-msg-for="password" val-toggle-msg="minlength">Minimum {{invitedUserPasswordModel.passwordPolicies.minPasswordLength}} characters</span>
                        <span class="help-inline" val-msg-for="password" val-toggle-msg="valServerField"></span>
                    </div>

                    <div class="control-group" ng-class="{error: setPasswordForm.confirmPassword.$invalid}">
                        <label><localize key="user_confirmNewPassword">Confirm new password</localize></label>
                        <input type="password" ng-model="invitedUserPasswordModel.confirmPassword" name="confirmPassword" class="-full-width-input" required val-compare="password" />
                        <span class="help-inline" val-msg-for="confirmPassword" val-toggle-msg="required"><localize key="general_required">Required</localize></span>
                        <span class="help-inline" val-msg-for="confirmPassword" val-toggle-msg="valCompare"><localize key="user_passwordMismatch">The confirmed password doesn't match the new password!</localize></span>
                    </div>

                    <div class="flex justify-between items-center">
                        <umb-button type="submit"
                                    button-style="success"
                                    state="invitedUserPasswordModel.buttonState"
                                    label="Save password">
                        </umb-button>
                    </div>

                </div>
            </form>

            <div class="form" ng-if="inviteStep === 2">

                <div class="flex justify-center items-center">

                    <ng-form name="avatarForm">

                        <umb-progress-bar style="max-width: 100px; margin-bottom: 5px;"
                                          ng-show="avatarFile.uploadStatus === 'uploading'"
                                          progress="{{ avatarFile.uploadProgress }}"
                                          size="s">
                        </umb-progress-bar>

                        <div class="umb-info-local-item text-error mt3" ng-if="avatarFile.uploadStatus === 'error'">
                            {{ avatarFile.serverErrorMessage }}
                        </div>

                        <a class="umb-avatar-btn"
                           ngf-select
                           ng-model="avatarFile.filesHolder"
                           ngf-change="changeAvatar($files, $event)"
                           ngf-multiple="false"
                           ngf-pattern="{{avatarFile.acceptedFileTypes}}"
                           ngf-max-size="{{ avatarFile.maxFileSize }}">

                            <umb-avatar color="gray"
                                        size="xl"
                                        unknown-char="+"
                                        img-src="{{invitedUser.avatars[3]}}"
                                        img-srcset="{{invitedUser.avatars[4]}} 2x, {{invitedUser.avatars[4]}} 3x">
                            </umb-avatar>
                        </a>

                    </ng-form>
                </div>

                <h1 style="margin-bottom: 10px;">Upload a photo</h1>
                <p style="text-align: center; margin-bottom: 25px; line-height: 1.6em;">
                    <localize key="user_userinviteAvatarMessage"></localize>
                </p>
                <div class="flex justify-center items-center">
                    <umb-button type="button"
                                button-style="success"
                                label="Done"
                                action="getStarted()">
                    </umb-button>
                </div>
            </div>
           
        </div>
        <div ng-show="invitedUser == null && inviteStep === 3" ng-if="inviteStep === 3" class="umb-login-container">
            <div class="form">
                <h1 style="margin-bottom: 10px; text-align: left;">Hi there</h1>
                <p style="line-height: 1.6; margin-bottom: 25px;">
                    <localize key="user_userinviteExpiredMessage">Welcome to Umbraco! Unfortunately your invite has expired. Please contact your administrator and ask them to resend it.</localize>
                </p>

            </div>
        </div>
        <div ng-show="invitedUser == null && !inviteStep" class="umb-login-container">

            <div class="form">
                <h1>{{greeting}}</h1>

                <div ng-show="view == 'login'">

                    <p>
                        <span ng-show="dialogData.isTimedOut"><localize key="login_timeout">Log in below</localize>.</span>
                    </p>

                    <div class="external-logins" ng-if="externalLoginProviders.length > 0">

                        <div class="text-error" ng-repeat="error in externalLoginInfo.errors">
                            <span>{{error}}</span>
                        </div>

                        <form method="POST" name="externalLoginForm" action="{{externalLoginFormAction}}">

                            <div ng-repeat="login in externalLoginProviders">

                                <button type="submit" class="btn btn-block btn-social"
                                        ng-class="login.properties.SocialStyle"
                                        id="{{login.authType}}" name="provider" value="{{login.authType}}"
                                        title="Log in using your {{login.caption}} account">
                                    <i class="fa" ng-class="login.properties.SocialIcon"></i>
                                    <localize key="login_signInWith">Sign in with</localize> {{login.caption}}
                                </button>

                            </div>
                        </form>

                    </div>

                    <form method="POST" name="loginForm" ng-submit="loginSubmit(login, password)">

                        <div class="control-group" ng-show="loginForm.$invalid">
                            <div class="text-error">{{errorMsg}}</div>
                        </div>

                        <div class="control-group" ng-class="{error: loginForm.username.$invalid}">
                            <label><localize key="general_username">Username</localize></label>
                            <input type="text" ng-model="login" name="username" class="-full-width-input" localize="placeholder" placeholder="@placeholders_usernameHint" />
                        </div>

                        <div class="control-group" ng-class="{error: loginForm.password.$invalid}">
                            <label><localize key="general_password">Password</localize></label>
                            <input type="password" ng-model="password" name="password" class="-full-width-input" localize="placeholder" placeholder="@placeholders_password" />
                            <div class="password-toggle">
                                <a href="#" prevent-default ng-click="togglePassword()">
                                    <span class="password-text show"><localize key="login_showPassword">Show password</localize></span>
                                    <span class="password-text hide"><localize key="login_hidePassword">Hide password</localize></span>
                                </a>
                            </div>
                        </div>

                        <div class="flex justify-between items-center">
                            <umb-button button-style="success"
                                        size="m"
                                        label-key="general_login"
                                        state="loginStates.submitButton"
                                        type="submit">
                            </umb-button>
                            <div ng-show="allowPasswordReset">
                                <a class="muted" style="text-decoration: underline;" href="#" prevent-default ng-click="showRequestPasswordReset()"><localize key="login_forgottenPassword">Forgotten password?</localize></a>
                            </div>
                        </div>

                    </form>
                </div>

                <div ng-show="view == 'request-password-reset'">
                    <p>
                        <localize key="login_forgottenPasswordInstruction">An email will be sent to the address specified with a link to reset your password</localize>
                    </p>

                    <form method="POST" name="requestPasswordResetForm" ng-submit="requestPasswordResetSubmit(email)">
                        <div class="control-group" ng-class="{error: requestPasswordResetForm.email.$invalid}">
                            <label><localize key="general_email">Email</localize></label>
                            <input type="email" val-email ng-model="email" name="email" class="-full-width-input" localize="placeholder" placeholder="@placeholders_email" />
                        </div>

                        <div class="control-group" ng-show="requestPasswordResetForm.$invalid">
                            <div class="text-error">{{errorMsg}}</div>
                        </div>

                        <div class="control-group" ng-show="showEmailResetConfirmation">
                            <div class="text-info">
                                <localize key="login_requestPasswordResetConfirmation">An email with password reset instructions will be sent to the specified address if it matched our records</localize>
                            </div>
                        </div>

                        <div class="flex justify-between items-center">
                            <button type="submit" class="btn btn-success" val-trigger-change="#login .form input"><localize key="general_submit">Submit</localize></button>
                            <a class="muted" href="#" prevent-default ng-click="showLogin()" style="text-decoration: underline;"><localize key="login_returnToLogin">Return to login form</localize></a>
                        </div>

                    </form>
                </div>

                <div ng-show="view == 'set-password'">

                    <p ng-hide="resetComplete">
                        <localize key="login_setPasswordInstruction">Please provide a new password.</localize>
                    </p>

                    <form method="POST" name="setPasswordForm" ng-submit="setPasswordSubmit(password, confirmPassword)">

                        <div ng-hide="resetComplete" class="control-group" ng-class="{error: setPasswordForm.password.$invalid}">
                            <label><localize key="user_newPassword">New password</localize></label>
                            <input type="password" ng-model="password" name="password" class="-full-width-input" localize="placeholder" placeholder="@placeholders_password" />
                        </div>

                        <div ng-hide="resetComplete" class="control-group" ng-class="{error: setPasswordForm.confirmPassword.$invalid}">
                            <label><localize key="user_confirmNewPassword">Confirm new password</localize></label>
                            <input type="password" ng-model="confirmPassword" name="confirmPassword" class="-full-width-input" localize="placeholder" placeholder="@placeholders_confirmPassword" />
                        </div>

                        <div ng-hide="resetComplete" class="control-group" ng-show="setPasswordForm.$invalid">
                            <div class="text-error">{{errorMsg}}</div>
                        </div>

                        <div class="control-group" ng-show="showSetPasswordConfirmation">
                            <div class="text-info">
                                <localize key="login_setPasswordConfirmation">Your new password has been set and you may now use it to log in.</localize>
                            </div>
                        </div>

                        <div class="flex justify-between items-center">
                            <button ng-hide="resetComplete" type="submit" class="btn btn-success" val-trigger-change="#login .form input"><localize key="general_submit">Submit</localize></button>
                            <a class="muted" href="#" prevent-default ng-click="showLogin()"><localize key="login_returnToLogin">Return to login form</localize></a>
                        </div>

                    </form>
                </div>

                <div ng-show="view == 'password-reset-code-expired'">
                    <div class="text-error" ng-repeat="error in resetPasswordCodeInfo.errors">
                        <span>{{error}}</span>
                    </div>

                    <div class="switch-view">
                        <a class="muted" href="#" prevent-default ng-click="showLogin()"><localize key="login_returnToLogin">Return to login form</localize></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
